package com.eunion.core.common.excel.exception;

import java.util.ArrayList;
import java.util.List;

import com.eunion.core.common.excel.ExcelImportWarning;

public class AbortImportException extends Exception {

    private final List<ExcelImportWarning> warnings;

    public static AbortImportException throwOut(List<ExcelImportWarning> warnings) {
        ExcelImportWarning lastWarning = warnings.get(warnings.size() - 1);
        String message = String.format("This import has aborted due to %s on %s(index:%d) on sheet %s.",
                lastWarning.getRootCause(), lastWarning.getColumnAlias(), lastWarning.getColumn(),
                lastWarning.getSheetName());
        return new AbortImportException(message, warnings);

    }

    private AbortImportException(String message, List<ExcelImportWarning> warnings) {
        super(message);
        this.warnings = warnings;
    }

    public List<ExcelImportWarning> getWarnings() {
        return new ArrayList<>(warnings);
    }

}
